import { Component } from '@angular/core';
import { NavController, NavParams, AlertController} from 'ionic-angular';
//充值
import { BalanceRechargePage } from '../balance-recharge/balance-recharge';
//提现
import { WithdrawcashPage } from '../withdrawcash/withdrawcash';
//明细
import { BalanceinfoPage } from '../balanceinfo/balanceinfo';

import { Https } from '../../app/http.service'
@Component({
    selector: 'page-list',
    templateUrl: 'list.html'
})
export class ListPage {
	balanceUrl = new Https().Url + "act=goods&op=app_my_balance"
    selectedItem: any;
    icons: string[];
    items: Array<{title: string, note: string, icon: string}>;
	balabce:string;
	constructor(public navCtrl: NavController, public navParams: NavParams, public alertCtrl: AlertController) {
		
    }

	ionViewWillEnter() {
		let then = this
		fetch(this.balanceUrl,{
			method:"post",
			headers: {
				'Content-Type': 'application/x-www-form-urlencoded'
			},
			body: "mid=" + localStorage.getItem("mid") + "&token=" + localStorage.getItem("token"),
		}).then((response)=>{
			response.text().then((con)=>{
				let resource = JSON.parse(con);
				then.balabce = resource['predeposit']
			})
		}).catch((err)=>{
			let confirm = then.alertCtrl.create({
				title: '温馨提示',
				message: err,
				buttons: [
					{ text: '确定' },

				]
			});
			confirm.present();
		})
	}

    itemTapped(event, item) {
      // That's right, we're pushing to ourselves!
      this.navCtrl.push(ListPage, {

        item: item
      });
    }
	balanceRecharge(){
		this.navCtrl.push(BalanceRechargePage);
	}
	newPage(int){
		if(int == 1){
      		this.navCtrl.push(BalanceinfoPage)
		}else if(int == 2){
			this.navCtrl.push(WithdrawcashPage, { url: this.balanceUrl})
		}
	}
}
